import { reactive } from 'vue'
export default class Tab {
  constructor() {
    this.list = reactive([
      {
        name: 'A',
        value: 1,
        children: [
          {
            name: 'A-1'
          },
          {
            name: 'A-2'
          },
          {
            name: 'A-3'
          }
        ]
      },
      {
        name: 'B',
        value: 2,
        children: [
          {
            name: 'B-1'
          },
          {
            name: 'B-2'
          },
          {
            name: 'B-3'
          }
        ]
      },
      {
        name: 'C',
        value: 3,
        children: [
          {
            name: 'C-1'
          },
          {
            name: 'C-2'
          },
          {
            name: 'C-3'
          }
        ]
      }
    ])
  }
  select(parent, item) {
    if (item.selected) {
      item.selected = false
      parent.selected = false
    } else {
      this.list.forEach((res) => {
        res.selected = false
        res.children.forEach((res) => (res.selected = false))
      })
      item.selected = true
      parent.selected = true
    }
  }
}
